<template>
	<view class="fill_wp">
		<div class="h"></div>
		<view class="fill_con bg_bai" style="margin-top: 0;">			
			<view class="item">
				<view class="span">开户行</view>
				<input class="uni_input" type="text" v-model="bankname" placeholder="请输入" />
			</view>
			<view class="item">
				<view class="span">银行卡号</view>
				<input class="uni_input" type="text" v-model="cardno" placeholder="请输入" />
			</view>
			<view class="item">
				<view class="span">持卡人</view>
				<input class="uni_input" type="idcard" v-model="owner" placeholder="请输入" />
			</view>
		</view>
		<view class="h"></view>
		<view class="food_btn">
			<view class="food_btn_con">
				<text class="btn btn_two" @click="SubMit()">保存</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bankname:'',
				cardno:'',
				owner:'',
			}
		},
		onLoad() {
			let that = this;
			if (that.common.GetStorage('byh5token')) {
				that.logintype = that.common.GetStorage('byh5type');				
				that.GetUserBank();
			} else {
				uni.reLaunch({
					url: '/pages/login/login',
				})
			}

		},
		methods: {
			SubMit:function(){
				let that = this;
				if (that.bankname == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入开户行',
						duration: 2000
					});
				}
				else if (that.cardno == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入银行卡号',
						duration: 2000
					});
				}
				else if (that.owner =='') {
					uni.showToast({
						icon: 'none',
						title: '请输入持卡人',
						duration: 2000
					});
				}
				else{
					let _data = {
						bankname:that.bankname,
						cardno:that.cardno,
						owner:that.owner,
					}
					uni.showLoading({
						title: '提交中...',
						mask: true
					});
					that.common.http('POST', 'user/bank', _data, function(res) {
						uni.showToast({
							icon: 'none',
							title: '修改成功！',
							duration: 2000
						});
						setTimeout(function() {
							that.navigateBack();
						}, 1500);
					});
				}
			},
			
			GetUserBank:function(){
				let that = this;
				uni.showLoading({
					title: '加载中...',
					mask: true
				});
				that.common.http('GET', 'user/bank', '', function(res) {
					uni.hideLoading();
					console.log(res.data);
					
					if(res.data){
						that.bankname = res.data.bankname;
						that.cardno = res.data.cardno;
						that.owner = res.data.owner;
					}
					
					
				});
			},
			
			navigateBack() {
				// #ifdef H5
				const pages = getCurrentPages()
				if (pages.length > 1) {
					uni.navigateBack(1)
					return;
				}
				//使用vue-router返回上一级
				let a = this.$router.go(-1)
				if (a == undefined) {}
				return;
				// #endif
				uni.navigateBack();
			},
		}
	}
</script>

<style scoped>	
	.mt30 {
		margin-top: 30rpx;
	}
</style>